/* Copyright (c) 2016-2020 Enfry Ltd. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of Enfry. 
 * You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with Enfry.
 */
package com.enfry.common.util;

import java.util.UUID;

import com.enfry.common.util.data.DateTimes;

/**
 * 
 * ID编号相关工具类
 * @Title com.enfry.util.Ids
 * @author Penghu
 * @date 2016年11月10日
 */
public class Ids
{
    private static final IntSequence sequence4 = new IntSequence(1, 9999);
    private static final IntSequence sequence5 = new IntSequence(1, 99999);
    
    /** 32位唯一ID号 */
    public static final String uuid()
    {
        return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
    }
    
    /** 16位唯一长整数，由12位秒级+4位序列号,JS支持最大值9007199254740992，所以16位在JSON中比较合适 */
    public static final long longId()
    {//TODO 还需要去处理2002年这种02开头的，以及2093年这种93大于JS最大值的，目前处于2014年，关系不大，后续处理
        long time = Long.parseLong(DateTimes.getDateTime12String());
        int seq = sequence4.next();
        
        return time * 10000 + seq;
    }
    
    /** 19位唯一长整数，由14位秒级+5位序列号 */
    public static final long longId19()
    {
        long time = Long.parseLong(DateTimes.getDateTime14String());
        int seq = sequence5.next();
        
        return time * 100000 + seq;
    }
}
